package divinity.weapons
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	
	import divinity.basic.*;
	import divinity.fx.particles.definitions.Standard;
	import divinity.utils.Filters;

	public class BeamWeapon extends Weapon
	{
		private var _fac:Number=1/300;
		private var _endX:Number;
		private var _endY:Number;
		public function BeamWeapon(wld:DivinityWorld,firedBy:*,direction:Point)
		{
			super(wld,firedBy,direction);
		}
		override public function init(e:Event)
		{
			_img=new DivinityObject();
			addChild(_img);
			getCollision();
			super.init(e);	
			//world.vfx.anim("explosion",this,500,.4);
			//world.vfx.makeVFX(this,30,Standard.BEAM_TRAIL);
			
		}
		private function getCollision()
		{
			var tx:Number;
			var ty:Number;
			var n:int=0;
			_img.graphics.lineStyle(2,0xaaffff,1);
			_img.graphics.moveTo(0,0);
			var me:Object;
			while(n<1000)
			{
				tx=Math.round(x+(n*vx));
				ty=Math.round(y+(n*vy));
				_img.graphics.lineTo(n*vx,n*vy);
				var checkHeight:int=world.getHeight(tx,ty);
				//trace("checking",tx,ty,checkHeight);
				if(n%5==4)
				{
					me={x:tx,y:ty};
					world.vfx.makeVFX(me,1,Standard.BEAM_TRAIL);
				}
				
				if(checkHeight>myHeight)
				{
					
					_endX=tx;
					_endY=ty;
					world.vfx.makeVFX(me,20,Standard.BEAM_EXPLOSION);
					world.vfx.shake(20,10);
					break;
				}
				if(tx>world.worldWidth)
				{
					_endX=tx;
					_endY=ty;
					break;
				}
				if(tx<0)
				{
					_endX=tx;
					_endY=ty;
					break;
				}
				if(ty>world.worldHeight)
				{
					_endX=tx;
					_endY=ty;
					break;
				}
				if(ty<0)
				{
					_endX=tx;
					_endY=ty;
					break;
				}
				n++;
			}	
			Filters.addFilters(_img,"GlowFilter,quality:3,color:0xffffff,blurX:10,blurY:10,strength:2");
		}
		override protected function moving():void
		{
			
		}
		override protected function makeMove():void
		{
			if(alpha>0)
			{
				//trace(_fac*_elapsed);
				alpha-=_fac*_elapsed;
				
			}
			else
			{
				alpha=0;
				alive=false;
			}
			
			
		}
		
		public function get fac():Number
		{
			return _fac;
		}
		
		public function set fac(value:Number):void
		{
			_fac = value;
		}
		override public function set img(objectImage:*):void		
		{
			
		}
		
	}
}